package com.hongdee.crm.schedule.controller;

import com.hongdee.crm.schedule.Config;
import com.hongdee.crm.task.service.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * Created by My on 2017/4/11.
 */
@RestController
@RequestMapping("/crm/schedule")
public class CrmScheduleController {
    private Logger logger = LoggerFactory.getLogger(Config.class);
    //流失车辆计算
    //基盘车辆计算
    @Autowired
    private ICarBaseCountService carBaseCountService;
    @Autowired
    private ITCrmTimeTaskService crmTimeTaskService;
    @Autowired
    private ITCrmCarWorkorderTaskService crmCarWorkorderTaskService;
    @Autowired
    private ITCrmCarPropertyTaskService itCrmCarPropertyTaskService;
    //工单
    @Autowired
    private ITCrmCarWorkorderTaskService itCrmCarWorkorderTaskService;
    //保养
    @Autowired
    private ITCrmCarMaintainMileTaskService itCrmCarMaintainMileTaskService;
    @Autowired
    private ITCrmCarWarrantyTaskService itCrmCarWarrantyTaskService;
    //回厂
    @Autowired
    private ITCrmCarBackToFacTaskService itCrmCarBackToFacTaskService;
    /*首保*/
    @Resource(name = "firstCarMaintainTaskService")
    private ITCrmCarMaintainTaskService crmCarMaintainTaskService;
    /*二保*/
    @Resource(name = "TwoCarMaintainTaskService")
    private ITCrmCarMaintainTaskService twoCrmCarMaintainTaskService;
    /*定保*/
    @Resource(name = "dbCarMaintainTaskService")
    private ITCrmCarMaintainTaskService dbCarMaintainTaskService;
    private Config config;

    /**
     * 手动执行延保类任务
     * 刷新延保记录车辆ID及车型
     * @throws Exception
     */
    @RequestMapping("/updateExCarSeriesQuartz")
    @ResponseBody
    public void updateExCarSeriesQuartz() throws Exception {
        carBaseCountService.updateExCarSeriesQuartz();
    }
    /**
     * 手动执行新续类任务
     * 刷新续保记录车辆ID及车型
     * @throws Exception
     */
    @RequestMapping("/updateInCarInfoQuartz")
    @ResponseBody
    public void updateInCarInfoQuartz() throws Exception {
        carBaseCountService.updateInCarInfoQuartz();
        crmTimeTaskService.maintainTimeTaskDay();
    }/**
     * 手动执行工单类任务
     * 更新与保养有关定时任务
     * 更新车辆工单车辆ID，更新车辆工单维修类别，更新车辆工单产值
     * 根据工单生成保养工单,更新车辆行驶里程,延保,质保,更新未处理任务信息
     * @throws Exception
     */
    @RequestMapping("/maintainTimeTaskDay")
    @ResponseBody
    public void maintainTimeTaskDay() throws Exception {
        crmTimeTaskService.maintainTimeTaskDay();
    }
    ///**
    // * 手动执行工单类任务
    // * 更新车辆工单车辆ID
    // * @throws Exception
    // */
    //@RequestMapping("/updWorkOrderCaridInfoQuartz")
    //@ResponseBody
    //public void updWorkOrderCaridInfoQuartz() throws Exception {
    //    crmCarWorkorderTaskService.updWorkOrderCaridInfoQuartz();
    //}
    ///**
    // * 手动执行工单类任务
    // * 更新车辆工单维修类别
    // * @throws Exception
    // */
    //@RequestMapping("/bulidWorkorderPropertyQuartz")
    //@ResponseBody
    //public void bulidWorkorderPropertyQuartz() throws Exception {
    //    crmCarWorkorderTaskService.bulidWorkorderPropertyQuartz();
    //}
    ///**
    // * 手动执行工单类任务
    // * 更新车辆工单产值
    // * @throws Exception
    // */
    //@RequestMapping("/updWorkOrderAmountInfoQuartz")
    //@ResponseBody
    //public void updWorkOrderAmountInfoQuartz() throws Exception {
    //    crmCarWorkorderTaskService.updWorkOrderAmountInfoQuartz();
    //}
    ///**
    // * 手动执行工单类任务
    // * 根据工单生成保养工单
    // * @throws Exception
    // */
    //@RequestMapping("/createCarMaintainMileQuartz")
    //@ResponseBody
    //public void createCarMaintainMileQuartz() throws Exception {
    //    crmCarMaintainMileTaskService.createCarMaintainMileQuartz();
    //}
    ///**
    // * 手动执行车辆类任务
    // * 更新车辆行驶里程
    // * @throws Exception
    // */
    //@RequestMapping("/updateRunMileQuartz")
    //@ResponseBody
    //public void updateRunMileQuartz() throws Exception {
    //    carBaseCountService.updateRunMileQuartz();
    //}
    ///**
    // * 手动执行延保类任务
    // * 延保
    // * @throws Exception
    // */
    //@RequestMapping("/updCarExsuranceInfoQuartz")
    //@ResponseBody
    //public void updCarExsuranceInfoQuartz() throws Exception {
    //    crmCarWarrantyTaskService.updCarExsuranceInfoQuartz();
    //}
    ///**
     /** 手动执行质保类任务
     * 质保
     * @throws Exception
     */
    @RequestMapping("/updCarWarrantyInfoQuartz")
    @ResponseBody
    public void updCarWarrantyInfoQuartz() throws Exception {
        itCrmCarWarrantyTaskService.updCarWarrantyInfoQuartz();
    }
    /**
     * 手动执行首保、二保、定保月度任务
     * @throws Exception
     */
    @RequestMapping("/maintainMonthTask")
    @ResponseBody
    public void maintainMonthTask()throws Exception{
        crmTimeTaskService.maintainTimeTaskMonth();
    }
    /**
     * 手动执行保险、关爱、年审、流失类任务
     * @throws Exception
     */
    @RequestMapping("/bgnlDayTask")
    @ResponseBody
    public void bgnlDayTask()throws Exception{
        crmTimeTaskService.bngTaskDay();
    }
    /**
     * 手动执行车辆相关任务
     * 回厂相关定时任务,更新任务回厂标志
     * @throws Exception
     */
    @RequestMapping("/carBackFacTaskDay")
    @ResponseBody
    public void carBackFacTaskDay()throws Exception{
        //回厂相关定时任务
        crmTimeTaskService.carBackFacTaskDay();
    }
    /**
     * 手动执行车辆相关任务
     * 更新车辆销售数据
     * @throws Exception
     */
    @RequestMapping("/updFromCompanyQuartz")
    @ResponseBody
    public void updFromCompanyQuartz()throws Exception{
        //更新车辆销售数据
        crmTimeTaskService.updFromCompanyQuartz();
    }
    /**
     * 手动执行车辆相关任务
     * 更新车辆标签信息
     * @throws Exception
     */
    @RequestMapping("/carlabelTaskDay")
    @ResponseBody
    public void carlabelTaskDay()throws Exception{
        //更新车辆标签信息
        crmTimeTaskService.carlabelTaskDay();
    }
    /**
     * 手动执行车辆相关任务
     * 更新SAID
     * @throws Exception
     */
    @RequestMapping("/updCrmTaskSaIdQuartz")
    @ResponseBody
    public void updCrmTaskSaIdQuartz()throws Exception{
        //更新SAID
        crmTimeTaskService.updCrmTaskSaIdQuartz();
    }
    /**
     * 计算流失车辆数据
     */
    @RequestMapping("/crateLostCar")
    @ResponseBody
    public void crateLostCar() throws Exception{
        config.crateLostCar();
    }
    /**
     * 计算基盘数据
     */
    @RequestMapping("/createBase")
    @ResponseBody
    public void createBase() throws Exception{
        config.createBase();
    }
    /**
     * 重新计算一下车龄
     */
    @RequestMapping("/createAge")
    @ResponseBody
    public void createAge() throws Exception{
        config.createAge();
    }
    /**
     * 流失返还标签
     */
    @RequestMapping("/lostBackLable")
    @ResponseBody
    public void lostBackLable() throws Exception{
        itCrmCarPropertyTaskService.carLossToBackLabelTaskQuartz();
    }
    /**
     * 流失标签
     */
    @RequestMapping("/lostLable")
    @ResponseBody
    public void lostLable() throws Exception{
        itCrmCarPropertyTaskService.carLossLabelTaskQuartz();
    }
    /**
     * 手动执行计算基盘新车增长
     */
    @RequestMapping("/countBaseCarQuartz")
    @ResponseBody
    public void countBaseCarQuartz() throws Exception{
        carBaseCountService.countBaseCarQuartz();
    }
    /**
     * 手动计算基盘流失数量
     */
    @RequestMapping("/countLostCarQuartz")
    @ResponseBody
    public void countLostCarQuartz() throws Exception{
        carBaseCountService.countLostCarQuartz();
    }
    /**
     * 手动刷新车辆行驶里程
     */
    @RequestMapping("/updateRunMileQuartz")
    @ResponseBody
    public void updateRunMileQuartz() throws Exception{
        carBaseCountService.updateRunMileQuartz();
    }
    /**
     * 手动刷新工单维修类型
     */
    @RequestMapping("/bulidWorkorderPropertyQuartz")
    @ResponseBody
    public void bulidWorkorderPropertyQuartz() throws Exception{
        itCrmCarWorkorderTaskService.bulidWorkorderPropertyQuartz();
    }
    /**
     * 手动刷新工单产值
     */
    @RequestMapping("/updWorkOrderAmountInfoQuartz")
    @ResponseBody
    public void updWorkOrderAmountInfoQuartz() throws Exception{
        itCrmCarWorkorderTaskService.updWorkOrderAmountInfoQuartz();
    }
    /**
     * 手动刷新工单车辆ID
     */
    @RequestMapping("/updWorkOrderCaridInfoQuartz")
    @ResponseBody
    public void updWorkOrderCaridInfoQuartz() throws Exception{
        itCrmCarWorkorderTaskService.updWorkOrderCaridInfoQuartz();
    }
    /**
     * 手动生成车辆保养工单
     */
    @RequestMapping("/createCarMaintainMileQuartz")
    @ResponseBody
    public void createCarMaintainMileQuartz() throws Exception{
        itCrmCarMaintainMileTaskService.createCarMaintainMileQuartz();
    }
    /**
     * 手动刷入续保合同结束日期
     */
    @RequestMapping("/updInsuranceEndDateQuartz")
    @ResponseBody
    public void updInsuranceEndDateQuartz() throws Exception{
        crmTimeTaskService.updInsuranceEndDateQuartz();
    }
    /**
     * 手动刷入续保类型
     */
    @RequestMapping("/updateInTypeQuartz")
    @ResponseBody
    public void updateInTypeQuartz() throws Exception{
        carBaseCountService.updateInTypeQuartz();
    }
    /**
     * 手动更新保养回厂任务
     */
    @RequestMapping("/carMaintainBackToFacQuartz")
    @ResponseBody
    public void carMaintainBackToFacQuartz() throws Exception{
        itCrmCarBackToFacTaskService.carMaintainBackToFacQuartz();
    }
    /**
     * 手动更新流失上月回厂
     */
    @RequestMapping("/carLsBeforeMonthBackToFacQuartz")
    @ResponseBody
    public void carLsBeforeMonthBackToFacQuartz() throws Exception{
        itCrmCarBackToFacTaskService.carLsTaskBackToFacQuartz();
    }
    /**
     * 手动更新流失本月回厂
     */
    @RequestMapping("/carLsBackToFacQuartz")
    @ResponseBody
    public void carLsBackToFacQuartz() throws Exception{
        itCrmCarBackToFacTaskService.carLsTaskBackToFacQuartz();
    }
    /**
     * 手动执行首保 首保月定时任务
     */
    @RequestMapping("/carFirstMaintainQuartz")
    @ResponseBody
    public void carFirstMaintainQuartz() throws Exception{
        crmCarMaintainTaskService.carMaintainQuartz();
    }
    /**
     * 手动执行二保 二保月定时任务
     */
    @RequestMapping("/carTwoMaintainQuartz")
    @ResponseBody
    public void carTwoMaintainQuartz() throws Exception{
        twoCrmCarMaintainTaskService.carMaintainQuartz();
    }
    /**
     * 手动执行定保 定保月定时任务
     */
    @RequestMapping("/carDbMaintainQuartz")
    @ResponseBody
    public void carDbMaintainQuartz() throws Exception{
        dbCarMaintainTaskService.carMaintainQuartz();
    }
    /**
     * 手动执行定时任务关爱 生日提醒
     */
    @RequestMapping("/guanAiShengRiQuartz")
    @ResponseBody
    public void guanAiShengRiQuartz() throws Exception{
        crmTimeTaskService.guanAiShengRiQuartz();
    }
    /**
     * 手动执行定时任务关爱 延保提醒
     */
    @RequestMapping("/guanAiYanBaoQuartz")
    @ResponseBody
    public void guanAiYanBaoQuartz() throws Exception{
        crmTimeTaskService.guanAiYanBaoQuartz();
    }
    /**
     * 手动执行定时任务关爱 年审提醒
     */
    @RequestMapping("/nianShenQuartz")
    @ResponseBody
    public void nianShenQuartz() throws Exception{
        crmTimeTaskService.nianShenQuartz();
    }
    /**
     * 手动执行定时任务关爱 质保任务
     */
    @RequestMapping("/guanAiZhiBaoQuartz")
    @ResponseBody
    public void guanAiZhiBaoQuartz() throws Exception{
        crmTimeTaskService.guanAiZhiBaoQuartz();
    }
    /**
     * 手动执行定时任务流失提醒
     */
    @RequestMapping("/liuShiQuartz")
    @ResponseBody
    public void liuShiQuartz() throws Exception{
        crmTimeTaskService.liuShiQuartz();
    }
    /**
     * 手动执行定时任务保险 次年交强险提醒
     */
    @RequestMapping("/ciNianJiaoQiangQuartz")
    @ResponseBody
    public void ciNianJiaoQiangQuartz() throws Exception{
        crmTimeTaskService.ciNianJiaoQiangQuartz();
    }
    /**
     * 手动执行定时任务保险 次年商业险提醒
     */
    @RequestMapping("/ciNianShangYeQuartz")
    @ResponseBody
    public void ciNianShangYeQuartz() throws Exception{
        crmTimeTaskService.ciNianShangYeQuartz();
    }
    /**
     * 手动执行定时任务保险 续保商业险提醒
     */
    @RequestMapping("/xuBaoShangYeQuartz")
    @ResponseBody
    public void xuBaoShangYeQuartz() throws Exception{
        crmTimeTaskService.xuBaoShangYeQuartz();
    }
    /**
     * 手动执行定时任务保险 续保交强险提醒
     */
    @RequestMapping("/xuBaoJiaoQiangQuartz")
    @ResponseBody
    public void xuBaoJiaoQiangQuartz() throws Exception{
        crmTimeTaskService.xuBaoJiaoQiangQuartz();
    }
    /**
     * 手动执行定时任务保险 保险接待 商业险提醒
     */
    @RequestMapping("/jieDaiShangYeQuartz")
    @ResponseBody
    public void jieDaiShangYeQuartz() throws Exception{
        crmTimeTaskService.jieDaiShangYeQuartz();
    }
    /**
     * 手动执行定时任务保险 保险接待 交强险提醒
     */
    @RequestMapping("/jieDaiJiaoQiangQuartz")
    @ResponseBody
    public void jieDaiJiaoQiangQuartz() throws Exception{
        crmTimeTaskService.jieDaiJiaoQiangQuartz();
    }
    /**
     * 手动执行定时任务保险 活跃用户
     */
    @RequestMapping("/baoXianHuoYueQuartz")
    @ResponseBody
    public void baoXianHuoYueQuartz() throws Exception{
        crmTimeTaskService.baoXianHuoYueQuartz();
    }
    /**
     * 手动执行定时任务保险 非活跃用户
     */
    @RequestMapping("/baoXianFeiHuoYueQuartz")
    @ResponseBody
    public void baoXianFeiHuoYueQuartz() throws Exception{
        crmTimeTaskService.baoXianFeiHuoYueQuartz();
    }
}
